﻿
using Newtonsoft.Json;
using Service.src.NW.Enum;
using Service.src.NW.Model.Enum;
using Service.src.NW.Model.Folw;
using System.Diagnostics;

namespace Service.src.Model.Folw
{
    public class FlowNode : FlowBaseEntity
    {
        /// <summary>
        /// 节点 ID
        /// </summary>
        [JsonProperty("id")]
        public int id { get; set; }

        /// <summary>
        /// 启用 = 1 / 禁用 = 0
        /// </summary>
        [JsonProperty("enable")]
        public int enable { get; set; }

        [JsonProperty("name")]
        public string name { get; set; }

        [JsonProperty("label")]
        public string label { get; set; }

        [JsonProperty("group")]
        public GroupTypeEnum Group { get; set; }

        [JsonProperty("icon")]
        public string icon { get; set; }

        [JsonProperty("hasInput")]
        public bool hasInput { get; set; }

        [JsonProperty("hasOutput")]
        public bool hasOutput { get; set; }

        [JsonProperty("iconOnRight")]
        public bool iconOnRight { get; set; }

        [JsonProperty("style")]
        public Style style { get; set; }

        [JsonProperty("rect")]
        public Rect rect { get; set; }

        /// <summary>
        /// 节点超时时间
        /// </summary>
        public int NodeTimeOut { get; set; } = 0;

        /// <summary>
        /// 当前节点的输入值
        /// </summary>
        [JsonProperty("nodeInputParam")]
        public NodeInputParam NodeInputParam { get; set; }

        /// <summary>
        /// 当前节点执行结束之后的输出值
        /// </summary>
        //[JsonProperty("nodeOutParams")]
        public NodeOutParam NodeOutParam { get; set; }

        [JsonProperty("nodeType")]
        public NodeTypeEnum nodeType { get; set; }

        /// <summary>
        /// 节点状态
        /// 1 = 成功
        /// 0 = 失败
        /// -1 = 默认
        /// -2 = 静默执行
        /// </summary>
        [JsonProperty("nodeStatus")]
        public NodeStatusEnum NodeStatus { get; set; } = NodeStatusEnum.DEFAULT;

        public static int GeneratedId(FlowRoot Flow)
        {
            ++Flow.nodeNumber;
            int ID = Flow.nodeNumber;

            foreach (NodeProcessor item in Flow.processors)
            {
                if (item.id == ID)
                {
                    GeneratedId(Flow);
                    break;
                }
            }

            return int.Parse(Flow.Id.ToString() + ID);
        }

    }

    public class Style
    {
        [JsonProperty("height")]
        public int height { get; set; }

        [JsonProperty("width")]
        public int width { get; set; }

        [JsonProperty("color")]
        public string color { get; set; }

        [JsonProperty("backgroundColor")]
        public string backgroundColor { get; set; }

    }

    /// <summary>
    /// 节点-矩形的大小和位置
    /// </summary>
    public class Rect
    {

        [JsonProperty("x")]
        public int x { get; set; }

        [JsonProperty("y")]
        public int y { get; set; }

        [JsonProperty("w")]
        public int w { get; set; }

        [JsonProperty("h")]
        public int h { get; set; }
    }
}
